<template>
  <el-form :model="loginForm" @submit.native.prevent="handleLogin">
    <el-form-item label="Username">
      <el-input v-model="loginForm.username"></el-input>
    </el-form-item>
    <el-form-item label="Password">
      <el-input type="password" v-model="loginForm.password"></el-input>
    </el-form-item>
    <el-button type="primary" native-type="submit">Login</el-button>
  </el-form>
</template>

<script>
export default {
  data() {
    return {
      loginForm: {
        username: '',
        password: ''
      }
    }
  },
  methods: {
    handleLogin() {
      // 发送登录请求到后端
      this.$axios.post('http://localhost:8080/login', this.loginForm)
        .then(response => {
          if (response.data.success) {
            this.$router.push('/notes');
          } else {
            this.$message.error('Invalid credentials');
          }
        })
    }
  }
}
</script>

